package org.gwt.project.tools.quickfix;

import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.WorkspaceJob;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.ui.IMarkerResolution;
import org.gwt.project.tools.ToolsPlugin;

public class RemoveResource extends WorkspaceJob implements IMarkerResolution {
	
	private IMarker marker;
	
	public RemoveResource() {
		this("Delete resource...");
	}
	
	public RemoveResource(String label) {
		super(label);
	}

	@Override
	public String getLabel() {
		return getName();
	}

	@Override
	public void run(IMarker marker) {
		
		this.marker = marker;
		
		schedule();
		
	}

	@Override
	public IStatus runInWorkspace(IProgressMonitor monitor)
			throws CoreException {
		
		// Prepare
		marker.getResource().delete(false, new NullProgressMonitor());
				
		// Finished
		return ToolsPlugin.asOK("Resource deleted");
		
	}

}
